﻿using ProductMonitor.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProductMonitor.UserControls
{
    /// <summary>
    /// WorkShopDetailUC.xaml 的交互逻辑
    /// 
    /// 如果用mainWindow.Content = new MonitorUC();这样做会直接替换掉 MainWindow 的 Content，
    /// 导致 MainWindow 原有的所有内容（包括资源、样式、布局、ContentControl等）都被移除，
    /// 只剩下新的 UserControl。这会让样式、资源字典、甚至窗口布局全部丢失，界面变得异常简陋。
    /// </summary>
    public partial class WorkShopDetailUC :  UserControl
    {
        public WorkShopDetailUC()
        {
            InitializeComponent();
            this.DataContext = new MonitorUCVM();
        }
        private void BackButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = Window.GetWindow(this) as MainWindow; // 获取当前窗口的 MainWindow 实例
            mainWindow.MainContent. Content = new MonitorUC(); // 切换回 MonitorUC 用户控件
           
        }

        private void CloseDetail_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = Window.GetWindow(this) as MainWindow; // 获取当前窗口的 MainWindow 实例
            mainWindow.MainContent.Content = new WorkShopDetailUC(); // 切换回 MonitorUC 用户控件

        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            if (detail.Visibility != Visibility.Visible)
            {
                // 先显示，再做淡入动画
                detail.Opacity = 0;
                detail.Visibility = Visibility.Visible;

                DoubleAnimation fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(300));
                detail.BeginAnimation(UIElement.OpacityProperty, fadeIn);
            }
            else
            {
                // 淡出动画，动画结束后隐藏
                DoubleAnimation fadeOut = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(300));
                fadeOut.Completed += (s, a) =>
                {
                    detail.Visibility = Visibility.Collapsed;
                };
                detail.BeginAnimation(UIElement.OpacityProperty, fadeOut);
            }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // 动态设置 DataContext，确保命令和属性绑定生效
            this.DataContext = new MonitorUCVM();
        }
    }
 }
